package com.vast.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vast.admin.annotation.UseToken;
import com.vast.admin.entity.ApplyMsgUser;
import com.vast.admin.entity.enums.QueryOrderEnum;
import com.vast.admin.service.ApplyMsgUserService;
import com.vast.common.annotation.Log;
import com.vast.common.core.domain.entity.SysUser;
import com.vast.common.utils.SecurityUtils;
import com.vast.common.constant.MessageCode;
import com.vast.common.core.domain.Result;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manager/applyMsgUser")
public class ApplyMsgUserController {

    @Autowired
    private ApplyMsgUserService applyMsgUserService;

    @ApiOperation(value = "查询列表信息", notes = "通过条件查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "size", value = "分页条数", dataType = "int", defaultValue = "10", required = false),
            @ApiImplicitParam(paramType = "query", name = "current", value = "页码,起始值:1", dataType = "int", defaultValue = "1", required = false),
            @ApiImplicitParam(paramType = "query", name = "listMode", value = "是否集合模式:true不进行分页直接返回所有结果集", dataType = "boolean", defaultValue = "false", required = false),
            @ApiImplicitParam(paramType = "query", name = "queryItems", value = "查询条件,json集合", defaultValue = "account,EQ,13419519796;", dataType = "String", required = false),
            @ApiImplicitParam(paramType = "query", name = "orderField", value = "排序字段,多个','分隔", defaultValue = "create_time", dataType = "String",  required = false),
            @ApiImplicitParam(paramType = "query", name = "order", value = "排序类型: ASC/DESC", dataType = "QueryOrderEnum",  required = false)
    })
    @GetMapping("/page")
    public Result<IPage<ApplyMsgUser>> page(@ApiParam(hidden = true) Page<ApplyMsgUser> page, boolean listMode, String queryItems, String orderField, QueryOrderEnum order) {
        return new Result<>(MessageCode.SUCCESS, "获取成功", applyMsgUserService.queryList(page, listMode, queryItems, orderField,order));

    }

    @ApiOperation(value = "删除", notes = "删除")
    @UseToken
    @Log(title = "删除消息接收用户")
    @DeleteMapping("/delete")
    public Result<Boolean> delete(@RequestBody @ApiParam(name="ids",value="数据id数组,以','分隔",required=true) Long[] ids) {
        if(ids != null) {
			SysUser manager = SecurityUtils.getLoginUser().getUser();
            boolean flag  = applyMsgUserService.delete(manager, ids);
            if(flag){
                return new Result<>(MessageCode.SUCCESS, "删除成功");
            }else{
                return new Result<>(MessageCode.ERROR, "删除失败");
            }
        }else {
            return new Result<>(MessageCode.PARAM_ERROR, "参数错误");
        }
    }

    @ApiOperation(value = "添加", notes = "添加")
    @UseToken
    @PostMapping("/add")
    @Log(title = "添加消息接收用户")
    public Result<String> add( @RequestBody @ApiParam(name="customerIds",value="消息接收用户ID",required=true) Long[] customerIds) {
        if(customerIds != null && customerIds.length > 0) {
			SysUser manager = SecurityUtils.getLoginUser().getUser();
            applyMsgUserService.add(manager, customerIds);
            return new Result<>(MessageCode.SUCCESS, "添加成功", "");
        }else {
            return new Result<>(MessageCode.PARAM_ERROR, "参数错误");
        }
    }




}
